package com.show.mytest;

public class MyThread extends Thread { //创建MyThread类继承Thread类

    //提供无参构造
    public MyThread() {
    }
    // 有参构造
    public MyThread(String name) {
        super(name);
    }

    // 重写run方法,封装要运行的代码
    @Override
    public void run() {
        try {
            System.out.println("让线程睡两秒");
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        for (int i = 0; i < 100; i++) {
            System.out.println(Thread.currentThread().getName() + "正在第 " + (i + 1) + " 次循环");
        }
    }
}
